/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package br.com.webcrm.model;

import java.io.Serializable;
import java.util.List;
import javax.persistence.Basic;
import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.OneToMany;
import javax.persistence.SequenceGenerator;
import javax.persistence.Table;

/**
 *
 * @author Frederiko
 */
@Entity
@Table(name = "Questionarios")
@SequenceGenerator(name = "questionarios_idQuestionario_seq", sequenceName = "questionarios_idQuestionario_seq", allocationSize = 1)
@NamedQueries({
    @NamedQuery(name = "Questionario.findAll", query = "SELECT q FROM Questionario q"),
    @NamedQuery(name = "Questionario.findByIdQuestionario", query = "SELECT q FROM Questionario q WHERE q.idQuestionario = :idQuestionario"),
    @NamedQuery(name = "Questionario.findByNomeQuestionario", query = "SELECT q FROM Questionario q WHERE q.nomeQuestionario = :nomeQuestionario"),
    @NamedQuery(name = "Questionario.findByAtivo", query = "SELECT q FROM Questionario q WHERE q.ativo = :ativo")})
public class Questionario implements Serializable {
    private static final long serialVersionUID = 1L;
    @Id
    @GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "questionarios_idQuestionario_seq")
    @Column(name = "idQuestionario", nullable = false)
    private Integer idQuestionario;
    @Basic(optional = false)
    @Column(name = "nome_questionario", nullable = false, length = 60)
    private String nomeQuestionario;
    @Basic(optional = false)
    @Column(name = "ativo", nullable = false)
    private Boolean ativo;
    @OneToMany(cascade = CascadeType.ALL, mappedBy = "questionario", fetch = FetchType.LAZY)
    private List<QuestPergunta> listaPerguntas;

    public Questionario() {
    }

    public Questionario(Integer idQuestionario) {
        this.idQuestionario = idQuestionario;
    }

    public Questionario(Integer idQuestionario, String nomeQuestionario, boolean ativo) {
        this.idQuestionario = idQuestionario;
        this.nomeQuestionario = nomeQuestionario;
        this.ativo = ativo;
    }

    public Integer getIdQuestionario() {
        return idQuestionario;
    }

    public void setIdQuestionario(Integer idQuestionario) {
        this.idQuestionario = idQuestionario;
    }

    public String getNomeQuestionario() {
        return nomeQuestionario;
    }

    public void setNomeQuestionario(String nomeQuestionario) {
        this.nomeQuestionario = nomeQuestionario;
    }

    public Boolean getAtivo() {
    	if (ativo == null){
    		ativo = Boolean.TRUE;
    	}
        return ativo;
    }

    public void setAtivo(Boolean ativo) {
        this.ativo = ativo;
    }

    public List<QuestPergunta> getListaPerguntas() {
        return listaPerguntas;
    }

    public void setListaPerguntas(List<QuestPergunta> listaPerguntas) {
        this.listaPerguntas = listaPerguntas;
    }

    @Override
    public int hashCode() {
        int hash = 0;
        hash += (idQuestionario != null ? idQuestionario.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof Questionario)) {
            return false;
        }
        Questionario other = (Questionario) object;
        if ((this.idQuestionario == null && other.idQuestionario != null) || (this.idQuestionario != null && !this.idQuestionario.equals(other.idQuestionario))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return "br.com.attende.model.Questionario[idQuestionario=" + idQuestionario + "]";
    }

}
